#! /usr/bin/python

import math

def period (d):
    l = []
    a0 = int(math.sqrt(d))
    #l.append(a0)
    firstB = d-a0**2
    firstR = int((2*a0)/firstB)*firstB-a0
    b = 1
    r = a0
    while(1) :
        a = int((a0+r)*b/(d-r**2))        
        if (d-r**2)%b == 0: b = (d-r**2)/b
        else: b = d-r**2
        r = a*b -r
        if b == firstB and r == firstR and len(l) > 0:break
        l.append(a)
    return l

#print period(5), period(6), period(7), period(8), period(10)

def convergent (D, pos):
    if pos == 1: return int(math.sqrt(D))

    l = period(D)
    index = pos-1
    n = 1
    d = l[(index-1)%len(l)]
    index -=1
    while(index >= 0):
        if index == 0: 
           a = int(math.sqrt(D))
           #print "index is 0", a, d
        else: 
           a = l[(index-1)%len(l)]
        #print n, d, a, index
        nextD = a*d + n
        nextN = d
        d = nextD
        n = nextN
        index -=1
    return d, n

preX = 0
maxD = 0

for d in range(2, 1001):
    n = int(math.sqrt(d))
    if n**2 == d: continue
    i = 2
    while (1):
        x, y = convergent(d, i)
        i +=1
        if x**2 - d*y**2 == 1: break
    if x > preX: 
       preX=x
       maxD = d
print preX, maxD
